package com.into.common.csv.converters.appenders;

import org.apache.commons.beanutils.PropertyUtils;

import com.into.common.csv.CSVField;
import com.into.common.csv.CSVOnlyValueConverter;


public abstract class ValueAppenderConverter<T> implements
		CSVOnlyValueConverter<T> {

	@SuppressWarnings("unchecked")
	@Override
	public T setFromString(String value, Object instance,
			CSVField<?> field) throws Exception {
		T originalValue = (T) PropertyUtils.getProperty(instance, field.getName());
		T toSet = append(originalValue, value);
		PropertyUtils.setProperty(instance, field.getName(), toSet);
		return toSet;
	}

	protected abstract T append(T originalValue, String value);

}
